package com.pug.zixun.commons.result;

import com.pug.zixun.commons.enums.AdminResultInterface;
import com.pug.zixun.commons.enums.AdminSuccessResultEnum;

/**
 * @Description: Uniform return results
 * @Author: WengYu
 * @CreateTime: 2022/05/18 19:55
 */

public class Result {

    /**
     * 业务返回码
     */
    private Integer code;
    /**
     * 描述
     */
    private String message;
    /**
     * 结果集
     */
    private Object data;

    private Result(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 返回成功
     * @author wengyu
     * @date 2022/05/18 21:50
     * @param: data 返回数据
     * @return com.pug.zixun.common.result.Result
     */
    public static Result success(Object data){
        return new Result(AdminSuccessResultEnum.SERVER_SUCCESS.getCode(), AdminSuccessResultEnum.SERVER_SUCCESS.getMessage(), data);
    }

    /**
     * 返回失败
     * @author wengyu
     * @date 2022/05/18 21:50
     * @param: code 失败状态码
     * @param: msg 失败原因
     * @return com.pug.zixun.common.result.Result
     */

    public static Result fail(Integer code, String message){
        return new Result(code,message,null);
    }

    public static Result fail(AdminResultInterface adminResultEnum){
        return new Result(adminResultEnum.getCode(), adminResultEnum.getMessage(), null);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
